<?php

include_once "user.php";
//接收内容
$content = $_REQUEST['content'];

if (empty($content)) {
    header("location:liuyan.html");
}

//准备要写的内容
$data = [
    'username' => $_SESSION['user']['username'],
    'time' => date('Y-m-d H:i:s'),
    'content' => $content
];
//把内容转换为JSON字符串
$dataStr = json_encode($data, JSON_UNESCAPED_UNICODE) . PHP_EOL;

//写入文件
file_put_contents("data.json", $dataStr, FILE_APPEND);

header("location:view_liuyan.php");